function [ ] = plotFitScatterEmissions( Eit_model, Eit_data, filename, ...
    titleString, inlogs, optfig, Elim )
% Plot total costs under the emissions market and under the command and
%   control scenario
%
%   INPUTS:
%     Eit_model - Plant i emissions in period t, as simulated
%     Eit_data  - Plant i emissions in period t
%     filename  - File in which to print figure
%     titleString - Title of figure
%     inlogs - Whether to show emissions in logarithms
%     optfig - Figure options
%     Elim - Emissions axis limits

%% Data
if inlogs
    Eit_model = log(Eit_model);
    Eit_data  = log(Eit_data);
end

% Calculate correlation
[ rho, rho_p ] = corr(Eit_data,Eit_model);

%% Plot

% Lines
f0 = figure;
scatter( Eit_data, Eit_model, 'o', 'MarkerEdgeColor', 'b' ); hold on;
plot( Elim, Elim, 'k--', 'LineWidth', optfig.axisweight-0.5 );


% Figure formatting
set(gcf, 'Color'       , 'w', ...
    'position',[0 0 500 500]);
set(gca, optfig.labProp{:}, ...
         'Box'         , 'off'             , ...
         'LineWidth'   , optfig.axisweight);

% Axis labels
if inlogs
    xlabelString = 'Log emissions (kg)';
else
    xlabelString = 'Emissions (kg)';
end
xlabel([ xlabelString ', data' ],optfig.textProp{:});
ylabel([ xlabelString ', model' ],optfig.textProp{:});

% Title
title(titleString,optfig.textProp{:},'Interpreter','latex');

% Legend
% legend([s1, s3, s2] ,{'Eqb. bids','Shaded bids','Costs'},...
%     'Location','southoutside',...
%     'Orientation','vertical',...
%      optfig.legProp{:});
% legend boxoff;

% Axis limits must include zero
if nargin > 6
    xlim(Elim);
    ylim(Elim);
end

% Add correlation to plot
xl = xlim;
yl = ylim;
corr_string = sprintf('Corr: %3.2f (p-val=%3.2f)',rho,rho_p);
text(xl(2) - 4,yl(1)+1,corr_string,optfig.textProp{:});

hold off;

%% Export figure to file

% Crop whitespace 
fig = gcf;
fig.PaperPositionMode = 'auto';
fig.PaperSize = [7.4 7.4];
fig.PaperPosition = [0.25 0.25 6.95 6.95];

ax = gca;
ax.Position = [0.10 0.10 0.90 0.85];

% Save all figures
%[filepath, ~, ~] = fileparts(filename);
%if not(isfolder(filepath))
%    mkdir(filepath);
%end
%fprintf(1,'Writing %s to file ...\n',filename);
%print(f0,'-dpdf','-painters','-noui','-r600', filename);

end